package com.faung.consumer;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * Created by Fuang on 2018-1-6.
 */
@Component
public class Receiver {

    @RabbitListener(queues = "hello")
    @RabbitHandler
    public void process(String hello) {
        System.out.println("Receiver ： " + hello);
    }

    @RabbitListener(queues = "topicAQueue")
    @RabbitHandler
    public void topicAQueueHandler(String context) {
        System.out.println("------------------------topicAQueue=" + context);
    }

    @RabbitListener(queues = "topicBQueue")
    @RabbitHandler
    public void topicBQueueHandler(String context) {
        System.out.println("------------------------topicBQueue=" + context);
    }

    @RabbitListener(queues = "fanoutAQueue")
    @RabbitHandler
    public void fanoutAQueueHandler(String context) {
        System.out.println("------------------------fanoutAQueue=" + context);
    }

    @RabbitListener(queues = "fanoutBQueue")
    @RabbitHandler
    public void fanoutBQueueHandler(String context) {
        System.out.println("------------------------fanoutBQueue=" + context);
    }

    @RabbitListener(queues = "batchQueue")
    public void batchQueueHandler(String i, Message message, Channel channel) throws IOException, InterruptedException {
        System.out.println(Thread.currentThread().getName() + "---------------------" + i);
        Thread.sleep(1000);
    }
}
